﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TraumaCenterSystem.Utils
{
    public class JsonHelper
    {
        #region 返回处理过的时间的Json

        /// <summary>
        /// 返回处理过的时间的Json
        /// </summary>
        /// <param name="obj">实体对象</param>
        /// <returns></returns>
        public static string JsonDate(object obj)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
            return JsonConvert.SerializeObject(obj, Formatting.None, timeConverter);
        }

        /// <summary>
        /// Json转换为对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static T DeserializeObject<T>(string value)
        {
            return JsonConvert.DeserializeObject<T>(value);
        }

        #endregion
    }
}
